<template>
    <view :style="themeColor">
        <view class="page" >
    <view class="flex align-stretch benben-position-layout flex addConsign_flex_0"    :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
            <view   class='flex align-center justify-between flex-sub addConsign_fd0_0'      >
            <view   class='flex align-center addConsign_fd0_0_c0'   @tap.stop="handleJumpDiy" data-type="back" data-url="1"   >
        <text class='fu-iconfont2  addConsign_fd0_0_c0_c0'  >&#xE794;</text>
</view>
    <view   class='flex align-center'      >
        <text class='addConsign_fd0_0_c1_c0'    v-if= "id==''"  >添加取货人</text><text class='addConsign_fd0_0_c1_c0'    v-if= "id!=''"  >编辑地址</text>
</view>
    <view   class='flex align-center justify-end addConsign_fd0_0_c0'      >
        <text class='addConsign_fd0_0_c2_c0'    v-if= "id!=''" @tap.stop="popupShow1686733151756=true" >删除</text>
</view>
</view>

        </view>
<view :style="{height: (88+StatusBarRpx)+'rpx'}"  ></view>
<!---添加地址flex布局开始-->
 <view class="flex flex-direction align-stretch benben-flex-layout addConsign_flex_1"    >
            <view   class='flex align-center addConsign_fd1_0'      >
        <text class='addConsign_fd1_0_c0'  >联系人</text>
<input class='flex-sub addConsign_fd1_0_c1'   type="text" :placeholder="`请输入联系人`" confirm-type="done" :maxlength="15" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"  v-model="dataMessage.name" />
</view>
    <view   class='flex flex-wrap align-center addConsign_fd1_0'      >
        <text class='addConsign_fd1_1_c0'  >{{$t('联系电话')}}</text>
<input class='flex-sub addConsign_fd1_1_c1'   type="number" :placeholder="`请输入联系电话`" confirm-type="done" :maxlength="11" placeholder-style="color:rgba(191, 191, 191, 1);font-size:32rpx"  v-model="dataMessage.mobile" />
</view>
    <view   class='flex flex-wrap align-center justify-between addConsign_fd1_0'      >
        <text class='addConsign_fd1_2_c0'  >设为默认</text>
        <benben-switch   v-model="is_default" default-color='#dcdfe6' color='rgba(77, 199, 119, 1)' :disabled='false' :auto='true' size='96'      >
        </benben-switch>
</view>
<button class='addConsign_fd1_3'  @tap.stop="addAddressFunc()" v-if= " id==''" >保存</button><button class='addConsign_fd1_3_1'  @tap.stop="editAddressFunc()" v-if= " id!=''" >保存</button>
</view>
        
<!---添加地址flex布局结束-->
<benben-popup v-model="popupShow1686733151756" :mask="true" :mask-close-able="true"  mode='center' >
    <!---基础弹窗flex布局开始-->
 <view class="flex flex-direction flex-wrap align-center addConsign_flex_2"    >
        <text class='addConsign_fd2_0'  >确认删除吗?</text>
    <view   class='flex align-center'      >
        <button class='addConsign_fd2_1_c0'  @tap.stop="popupShow1686733151756=false"  >取消</button>
<button class='addConsign_fd2_1_c1'  @tap.stop="deleteAddressFunc()"  >确定</button>
</view>
</view>
        
<!---基础弹窗flex布局结束-->
    
</benben-popup>
<!--选择器开始 -->
        <benben-picker ref="benbenWritePickerCodepicker3" :visible.sync="pickerDiy1687776948467" :label.sync='dataMessage.address_code_area_str' :province.sync='dataMessage.address_code_province' :city.sync='dataMessage.address_code_city' :area.sync='dataMessage.address_code_district'  mode='region' :mask-show='true' :picker-height='88' :hide-area='false'  >
            <template #picker-header>
        <view   class='flex flex-wrap align-center justify-between addConsign_picker3_0'      >
        <text   @tap="$refs.benbenWritePickerCodepicker3.cancel()" >取消</text>
<text   >请选择所在地址</text>
<text class='addConsign_picker3_0_c2'  @tap="$refs.benbenWritePickerCodepicker3.pickerConfirm()" >确定</text>
</view>
</template>
        </benben-picker>
<!--选择器结束 -->
    
    
        </view>
    </view>
</template>
<script>
    import {validate} from '@/common/utils/validate.js'
    export default {
        components:{},
        
        
        data(){
			return {"pickerDiy1687776948467":false,"popupShow1686733151756":false,"is_default":false,"address":"","sex_type":[{"name":"先生","value":"1","image":""},{"name":"女士","value":"2","image":""}],"sex_id":"1","address_type":[{"name":"公司","value":"1","image":""},{"name":"家","value":"2","image":""}],"address_id":"1","dataMessage":{"aid":"","name":"","mobile":"","is_default":""},"real_name":"","dataEssay":[],"dataType":[],"dataDetails":[],"mapMessage":{"name":"","address":"","latitude":"","longitude":""},"datamap":{"lng":"","lat":"","area":"","province":"","city":"","district":""},"id":""};
		},
		computed:{
            themeColor() {
              return this.$store.getters.themeColor
            },
            
		},
		watch:{},
		onLoad(options){
            let {id}=options
if (id !== undefined) this.id = id
this.getaddressMessageFunc()
		},
        onUnload() {
                
        },
		onReady(){
            
		},
		onShow(){
            
		},
		onHide(){
            
		},
		onResize(){
            
		},
		onPullDownRefresh(){
            
		},
		onReachBottom(e){
            
		},
		onPageScroll(e){
            
		},
		methods:{
                            //添加地址
                async addAddressFunc(){
                                if(!validate(this.dataMessage.label_name,'require')){
                 this.$message.info('请选择地址标签');
                 return false;
            }
            if(!validate(this.dataMessage.real_name,'require')){
                 this.$message.info('请输入收货人名称');
                 return false;
            }
            if(!validate(this.dataMessage.mobile,'require')){
                 this.$message.info('请输入联系电话');
                 return false;
            }
            if(!validate(this.dataMessage.mobile,'phone')){
                 this.$message.info('请输入正确的手机号');
                 return false;
            }
            if(!validate(this.dataMessage.address_code_province,'require')){
                 this.$message.info('请选择省市区');
                 return false;
            }
            if(!validate(this.dataMessage.detail,'require')){
                 this.$message.info('请输入详细地址');
                 return false;
            }
    if( this.is_default===true){
           this.dataMessage.is_default = '1';
    }
    else{
           this.dataMessage.is_default = '0';
    }
    //请求方法
    //数据验证
    
  let data64633d17182ad = await this.$api.dbPost(global.apiUrls.post64633d17182ad, {
    name:this.dataMessage.name,mobile:this.dataMessage.mobile,is_default:this.is_default
  });
  if(!data64633d17182ad) return
  if (data64633d17182ad.data.code != 1) {
    this.$message.info(data64633d17182ad.data.msg);
    return
  } 
  
  
  
                    this.$message.info('添加成功');
                setTimeout(()=>{
                    this.$urouter.navigateBack(1);
      },500)
                },
                //获取单个地址
                async getaddressMessageFunc(){
                       this.dataMessage.sex = '1';
    if( this.id!=''){
            //请求方法
    //数据验证
    
  let datadataMessage = await this.$api.post(global.apiUrls.post6463409b95b15, {
    aid:this.id
  });
  
  if (datadataMessage.data.code != 1) {
    this.$message.info(datadataMessage.data.msg);
    return
  } 
  let infodataMessage = datadataMessage.data;
  this.dataMessage = infodataMessage.data
  
    }
    if( this.dataMessage.is_default=='1'){
           this.is_default = true;
    }
    else{
           this.is_default = false;
    }
                },
                //获取地址标签
                async getTypeFunc(){
                        //请求方法
    //数据验证
    
  let datadataType = await this.$api.get(global.apiUrls.post5ff6859e3c4fd, {
    
  });
  
  if (datadataType.data.code != 1) {
    this.$message.info(datadataType.data.msg);
    return
  } 
  let infodataType = datadataType.data;
  this.dataType = infodataType.data
  
                },
                //编辑地址
                async editAddressFunc(){
                                if(!validate(this.dataMessage.label_name,'require')){
                 this.$message.info('请选择地址标签');
                 return false;
            }
            if(!validate(this.dataMessage.real_name,'require')){
                 this.$message.info('请输入收货人名称');
                 return false;
            }
            if(!validate(this.dataMessage.mobile,'require')){
                 this.$message.info('请输入联系电话');
                 return false;
            }
            if(!validate(this.dataMessage.mobile,'phone')){
                 this.$message.info('请输入正确的联系电话');
                 return false;
            }
            if(!validate(this.dataMessage.address_code_province,'require')){
                 this.$message.info('请选择省市区');
                 return false;
            }
            if(!validate(this.dataMessage.detail,'require')){
                 this.$message.info('请输入详细地址');
                 return false;
            }
    if( this.is_default===true){
           this.dataMessage.is_default = '1';
    }
    else{
           this.dataMessage.is_default = '0';
    }
    //请求方法
    //数据验证
    
  let data64633e52cfd0d = await this.$api.dbPost(global.apiUrls.post64633e52cfd0d, {
    aid:this.dataMessage.aid,name:this.dataMessage.name,mobile:this.dataMessage.mobile,is_default:this.is_default
  });
  if(!data64633e52cfd0d) return
  if (data64633e52cfd0d.data.code != 1) {
    this.$message.info(data64633e52cfd0d.data.msg);
    return
  } 
  
  
  
                    this.$message.info('编辑成功');
                setTimeout(()=>{
                    this.$urouter.navigateBack(1);
      },500)
                },
                //地图选点
                async mapSelectFunc(){
                                    this.mapMessage = await this.syncUniApi('chooseLocation')
    //请求方法
    //数据验证
    
  let datadatamap = await this.$api.dbGet(global.apiUrls.post649e954010762, {
    lng:this.mapMessage.longitude,lat:this.mapMessage.latitude
  });
  if(!datadatamap) return
  if (datadatamap.data.code != 1) {
    this.$message.info(datadatamap.data.msg);
    return
  } 
  let infodatamap = datadatamap.data;
  this.datamap = infodatamap.data
  
    let str = this.mapMessage.address.replace(/.+?(省|市|自治区|自治州|县|区)/g,'')
this.dataMessage.detail = str;
   this.dataMessage.address_code_area_str = this.datamap.area;
   this.dataMessage.address_code_province = this.datamap.province;
   this.dataMessage.address_code_city = this.datamap.city;
   this.dataMessage.address_code_district = this.datamap.district;
                },
                //删除地址
                async deleteAddressFunc(){
                        //请求方法
    //数据验证
    
  let data636f773e8d763 = await this.$api.dbPost(global.apiUrls.post636f773e8d763, {
    address_id:this.id
  });
  if(!data636f773e8d763) return
  if (data636f773e8d763.data.code != 1) {
    this.$message.info(data636f773e8d763.data.msg);
    return
  } 
  
  
  
    this.popupShow1686733151756 = false;
                setTimeout(()=>{
                    this.$urouter.navigateBack(1);
      },500)
                }
		}
    };
</script> 
<style lang="scss" scoped>
           .page{
            width: 100vw;
            overflow-x: hidden;
            min-height: calc(100vh - var(--window-bottom));
            background:var(--benbenbgColor1);background-size: 100% auto;
        }
    .addConsign_flex_0{
        background:#fff;width:750rpx;height:88rpx;overflow:hidden;z-index:10;top:0rpx;background-size:100% auto !important;
    }
    .addConsign_fd0_0_c2_c0{
        color:#333333;font-size:32rpx;font-weight:500;line-height:45rpx;
    }
    .addConsign_fd0_0_c1_c0{
        font-size:36rpx;font-weight:500;color:#333;
    }
    .addConsign_fd0_0_c0_c0{
        font-size:32rpx;font-weight:500;color:#333;
    }
    .addConsign_fd0_0_c0{
        width:180rpx;
    }
    .addConsign_fd0_0{
        padding:0rpx 32rpx 0rpx 32rpx;line-height:88rpx;
    }
    .addConsign_flex_1{
        background:var(--benbenbgColor1);padding:0rpx 32rpx 0rpx 32rpx;background-size:100% auto !important;
    }
    .addConsign_fd1_3_1{
        background:var(--benbenbgColor7);border-radius:44rpx 44rpx 44rpx 44rpx;font-size:32rpx;color:var(--benbenFontColor3);width:686rpx;height:88rpx;line-height:88rpx;font-weight:500;
    }
    .addConsign_fd1_3{
        background:var(--benbenbgColor7);border-radius:44rpx 44rpx 44rpx 44rpx;font-size:32rpx;color:var(--benbenFontColor3);width:686rpx;height:88rpx;line-height:88rpx;font-weight:500;position:fixed;left:32rpx;bottom:calc(40rpx + var(--window-bottom));
    }
    .addConsign_fd1_2_c0{
        line-height:45rpx;font-size:32rpx;font-weight:400;color:#333333;
    }
    .addConsign_fd1_1_c1{
        font-size:32rpx;font-weight:400;color:#333;
    }
    .addConsign_fd1_1_c0{
        line-height:45rpx;font-size:32rpx;font-weight:400;color:#333333;width:168rpx;
    }
    .addConsign_fd1_0_c1{
        line-height:32rpx;font-size:32rpx;font-weight:400;color:#333;width:200rpx;
    }
    .addConsign_fd1_0_c0{
        line-height:45rpx;font-size:32rpx;font-weight:500;color:rgba(51, 51, 51, 1);width:168rpx;
    }
    .addConsign_fd1_0{
        border-bottom:1px solid #eee;padding:32rpx 0rpx 32rpx 0rpx;
    }
    .addConsign_flex_2{
        background:#fff;width:540rpx;border-radius:16rpx 16rpx 16rpx 16rpx;
    }
    .addConsign_fd2_1_c1{
        border-top:1px solid #eee;border-left:1px solid #eee;background:#fff;line-height:94rpx;border-radius:0rpx 0rpx 16rpx 0rpx;font-size:32rpx;color:var(--benbenFontColor5);padding:0rpx 98rpx 0rpx 101rpx;font-weight:500;
    }
    .addConsign_fd2_1_c0{
        border-top:1px solid #eee;background:#fff;line-height:94rpx;border-radius:0rpx 0rpx 0rpx 16rpx;font-size:32rpx;color:rgba(153, 153, 153, 1);padding:0rpx 102rpx 0rpx 103rpx;font-weight:400;
    }
    .addConsign_fd2_0{
        line-height:44rpx;font-size:32rpx;font-weight:500;color:#333333;margin:91rpx 0rpx 88rpx 0rpx;
    }
    .addConsign_picker3_0_c2{
        color:var(--benbenFontColor5);
    }
    .addConsign_picker3_0{
        border-bottom:1px solid #eee;background:#fff;padding:0rpx 32rpx 0rpx 32rpx;line-height:100rpx;border-radius:25rpx 25rpx 0rpx 0rpx;background-size:100% auto !important;font-size:32rpx;
    }
</style>